home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / B_FRPROC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  14.0 KB  |  420 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*               The Opus Computer-Based Conversation System                */
  3. /*       (c) Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  4. /*                                                                          */
  5. /*                   YOOHOO is a trademark of Wynn Wagner III               */
  6. /*                                                                          */
  7. /*                            YOOHOO-YOOHOO/2U2 is                          */
  8. /*           Copyright 1987, Wynn Wagner III, All Rights Reserved           */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*                   BinkleyTerm File Request Processor                     */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*  This module is a very simple FOSSIL-based terminal emulator. It is      */
  15. /*  provided for your information only.  You will find routines that need   */
  16. /*  to be coded and identifiers to be resolved. It has been previously      */
  17. /*  known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm"   */
  18. /*  does not preclude the possibility that another "OpusLink" or "OConnect" */
  19. /*  could be released.                                                      */
  20. /*                                                                          */
  21. /*  There is absolutely no guarantee that anything here will work.  If you  */
  22. /*  break this routine, you own both pieces.                                */
  23. /*                                                                          */
  24. /*  USAGE:  You may use this material in any program with no obligation     */
  25. /*          as long as there is no charge for your program.  For more       */
  26. /*          information about commercial use, contact the "OPUSinfo HERE"   */
  27. /*          BBS (124/111).                                                  */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*--------------------------------------------------------------------------*/
  31.  
  32. #include <signal.h>
  33. #include <ctype.h>
  34. #include <conio.h>
  35.  
  36. #define WAZOO_SECTION
  37. #include "zmodem.h"
  38.  
  39. #include "com.h"
  40.  
  41.  
  42. static int prep_match( template, buffer )
  43.    char *template;
  44.    char *buffer;
  45.    begin
  46.        register int   i,delim;
  47.       register char *sptr;
  48.       int            start;
  49.  
  50.       memset( buffer, 0, 11 );
  51.  
  52.       i     = strlen(template);
  53.       sptr  = template;
  54.  
  55.  
  56.       for(start=i=0; sptr[i]; i++)
  57.          if ((sptr[i]=='\\')  or (sptr[i]==':'))
  58.             start = i+1;
  59.  
  60.       if (start) sptr  += start;
  61.       delim = 8;                             /* last column for ? */
  62.  
  63.       strupr(sptr);
  64.  
  65.       for(i=0; *sptr && i < 12; sptr++)
  66.          switch(*sptr)
  67.              begin
  68.  
  69.                default  :  buffer[i++] = *sptr;
  70.                            break;
  71.  
  72.                case '.' :  if (i>8) return(-1);
  73.                            while(i<8)
  74.                               begin
  75.                                  buffer[i++] = ' ';           
  76.                               end
  77.                            buffer[i++] = *sptr;
  78.                            delim = 12;
  79.                            break;
  80.  
  81.                case '*' :  while(i<delim)
  82.                               begin
  83.                                  buffer[i++] = '?';
  84.                               end
  85.                            break;
  86.  
  87.              end /* switch */
  88.       while(i<12)
  89.          begin
  90.             if (i == 8)
  91.                buffer[i++] = '.';
  92.             else
  93.                 buffer[i++] = ' ';
  94.          end
  95.       buffer[i] = '\0';
  96.  
  97.    return 0;
  98.  
  99.  
  100.    end
  101.  
  102.  
  103.  
  104.  
  105. static int match (s1, s2 )
  106.    char *s1, *s2;
  107.    begin
  108.       register char *i,*j;
  109.  
  110.       i  = s1;
  111.       j  = s2;
  112.  
  113. /* cprintf("TRYING `%s' `%s'\r\n", s1, s2 ); */
  114.  
  115.       while(*i)
  116.          begin
  117.             if ((*j != '?') and (*i != *j))
  118.                begin
  119. /* cprintf("%c != %c\r\n", *i, *j ); */
  120.                   return 1;
  121.                end
  122. /* else cprintf("%c == %c\r\n",*i, *j ); */
  123.             i++;
  124.             j++;
  125.          end
  126.  
  127.       return 0;
  128.  
  129.    end
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140. /*--------------------------------------------------------------------------*/
  141. /* Process file requests from the remote system. The filespec requested is  */
  142. /* turned into a local filespec if possible, then returned to either the    */
  143. /* WaZOO or SEAdog file request logic.                                      */
  144. /*--------------------------------------------------------------------------*/
  145.  
  146. char *n_frproc(request, recno, updreq)
  147.    char *request;
  148.    int *recno;
  149.    int updreq;
  150.    begin
  151.       register int    i, j;
  152.       static char     s[80];
  153.       char            s1[80];
  154.       FILE           *approved;
  155.       struct FILEINFO dta;
  156.       char           *sptr;
  157.    
  158.       char           *their_pwd;
  159.       char            required_pwd[10];
  160.       char           *after_pwd;
  161.  
  162.       char            our_wildcard[15];
  163.       char            their_wildcard[15];
  164.       char            magic[15];
  165.    
  166.       approved    = NULL;
  167.       their_pwd   = NULL;
  168.       after_pwd   = NULL;
  169.       strcpy (s1, request);
  170.  
  171.       /*--------------------------------------------------------------------*/
  172.       /* Fix up the file name                                               */
  173.       /*--------------------------------------------------------------------*/
  174.       for(i=0; request[i]; i++)
  175.          if ((request[i]==' ') or (request[i]==0x09))
  176.             begin
  177.                request[i]  = '\0';
  178.                if (request[i+1]=='!')
  179.                   begin
  180.                      their_pwd   = request+i+2;
  181.                      if (strlen(their_pwd)>6) their_pwd[6] = '\0';
  182.                      fancy_str(their_pwd);
  183.                   end
  184.             end
  185.          else if (request[i]<=' ') request[i] = '\0';
  186.    
  187.       if (!request[0]) return NULL;
  188.  
  189.       if (their_pwd)
  190.          begin
  191.              for(i=0; their_pwd[i]; i++)
  192.                if (their_pwd[i] <= ' ') their_pwd[i] = '\0';
  193.          end
  194.  
  195.  
  196.       /*--------------------------------------------------------------------*/
  197.       /* Initialization(s)                                                  */
  198.       /*--------------------------------------------------------------------*/
  199.       i        =
  200.       errno    = 0;
  201.       sptr     = NULL;
  202.    
  203.       strupr(request);
  204.       if (*recno == -1)
  205.          status_line("*%s request (%s)", updreq?"Update":"File", request);
  206.    
  207.  
  208.       /*--------------------------------------------------------------------*/
  209.       /* Reserved words                                                     */
  210.       /*--------------------------------------------------------------------*/
  211.       if (*recno < 0)
  212.          {
  213.          if (!strcmp(request,"FILES"))
  214.             begin
  215.                if (ctl.avail_list)
  216.                   strcpy(s,ctl.avail_list);
  217.                else
  218.                   begin
  219.                      s[0] = '\0';
  220.                      sptr  = "No AVAIL list";
  221.                   end
  222.                goto avail;
  223.             end
  224.  
  225.          else if (!strcmp(request,"ABOUT"))
  226.             begin
  227.                s[0] = '\0';
  228.                goto avail;
  229.             end
  230.          }
  231.  
  232.       prep_match( request, their_wildcard );
  233.  
  234.  
  235.       /*--------------------------------------------------------------------*/
  236.       /* See if the file is approved for transmission                       */
  237.       /*--------------------------------------------------------------------*/
  238.       approved = fopen(ctl.request_list,read_ascii);
  239.       if (got_error(OPEN_msg,ctl.request_list)) goto err;
  240.  
  241.       j = -1;
  242.       magic[0] = '\0';
  243.       while(!feof(approved))
  244.          begin
  245.             /* If we had a magic name, copy back the old wildcard stuff */
  246.             if (magic[0])
  247.                {
  248.                strcpy (their_wildcard, magic);
  249.                magic[0] = '\0';
  250.                }
  251.  
  252.             s[0]              =
  253.             required_pwd[0]   = '\0';
  254.  
  255.             fgets(s,78,approved);
  256.  
  257.             for(i=0; s[i]; i++)
  258.                     if (s[i]==0x09) s[i] = ' ';
  259.                else if (s[i]<' ')   s[i] = '\0';
  260.  
  261.             if (!s[0]) continue;
  262.  
  263.             /*--------------------------------------------------------------*/
  264.             /* Check for transaction-level password                         */
  265.             /*--------------------------------------------------------------*/
  266.             for(i=0; s[i]; i++)
  267.                begin
  268.                   if (s[i]==' ')
  269.                      begin
  270.                         s[i]  = '\0';
  271.                         if (s[i+1]=='!')
  272.                            begin
  273.                               strncpy( required_pwd, s+i+2, 8 );
  274.                               if (strlen(required_pwd)>6) required_pwd[6] = '\0';
  275.  
  276.                               after_pwd = s+i+1;
  277.                               while (*after_pwd && (!isspace (*after_pwd)))
  278.                                  ++after_pwd;
  279.  
  280.                               if (*after_pwd)
  281.                                  ++after_pwd;
  282.  
  283.                               for(i=0; required_pwd[i]; i++)
  284.                                  if (required_pwd[i]<=' ') required_pwd[i] = '\0';
  285.  
  286.                               break;
  287.                            end
  288.                         else
  289.                            begin
  290.                               after_pwd = s+i+1;
  291.                            end
  292.                      end
  293.                   else if (s[i]<' ') s[i]=0;
  294.                end
  295.  
  296.  
  297.             if (!s[0]) continue;
  298.  
  299.             if ((s[0] == '$') || (s[0] == ';'))
  300.                continue;
  301.  
  302.             if (s[0] == '@')
  303.                {
  304.                /* Magic name */
  305.                if (stricmp (&(s[1]), request) == 0)
  306.                   {
  307.                   /* It matches */
  308.                   strcpy (magic, their_wildcard);
  309.                   strcpy (s, after_pwd);
  310.                   strcpy (their_wildcard, "????????.???");
  311.                   }
  312.                else
  313.                   {
  314.                   /* It doesn't match, so go on */
  315.                   continue;
  316.                   }
  317.                }
  318.  
  319.             if (!dfind(&dta,s,0))
  320.                begin
  321.                   do
  322.                      begin
  323.                         prep_match(dta.name,our_wildcard);
  324.  
  325.                         if (!match(our_wildcard,their_wildcard))
  326.                            begin
  327.                               for(i=strlen(s);i;i--)
  328.                                  if (s[i]=='\\')
  329.                                     begin
  330.                                        s[i+1]=0;
  331.                                        break;
  332.                                     end
  333.                               strcat(s,dta.name);
  334.  
  335.                               if (required_pwd[0])
  336.                                  begin
  337.                                     fancy_str(required_pwd);
  338.                                     if (  (strcmp(required_pwd,their_pwd)) and
  339.                                           (strcmp(required_pwd,remote_password))
  340.                                        )
  341.                                        begin
  342.                                           status_line("!Transaction pwd err: %s %s %s",
  343.                                                       required_pwd,
  344.                                                       their_pwd,
  345.                                                       remote_password
  346.                                                     );
  347.                                        end
  348.                                     else
  349.                                        {
  350.                                        if (++j > *recno)
  351.                                           goto gotfile;
  352.                                        }
  353.                                  end
  354.                               else
  355.                                  {
  356.                                  if (++j > *recno)
  357.                                     goto gotfile;
  358.                                  }
  359.                            end
  360.                      end
  361.                   while(!dfind(&dta));
  362.  
  363.                end /* if dfind */
  364.  
  365.             else status_line("!OKFILE ERR `%s'",s);
  366.  
  367.             s[0] = '\0';
  368.  
  369.          end /* while not eof(approved) */
  370.  
  371.  
  372.    
  373.       /*--------------------------------------------------------------------*/
  374.       /* File requested not found, send the system ABOUT file.              */
  375.       /*--------------------------------------------------------------------*/
  376. avail:
  377.       strcpy (request, s1);
  378.  
  379.       if (*recno > -1)
  380.          {
  381.          *recno = -1;
  382.          return (NULL);
  383.          }
  384.       if (!s[0])
  385.          begin
  386.             *recno = -1;
  387.             if (ctl.freq_about)
  388.                strcpy(s,ctl.freq_about);
  389.             else
  390.                begin
  391.                   sptr = "No ABOUT file";
  392.                   goto err;
  393.                end
  394.          end
  395.    
  396.       /*--------------------------------------------------------------------*/
  397.       /* Send a file                                                        */
  398.       /*--------------------------------------------------------------------*/
  399. gotfile:
  400.       strcpy (request, s1);
  401.  
  402.       ++(*recno);
  403.       if (approved) fclose(approved);
  404.       errno = 0;
  405.       fancy_str(s);
  406.       return s;
  407.  
  408.  
  409.       /*--------------------------------------------------------------------*/
  410.       /* Error return                                                       */
  411.       /*--------------------------------------------------------------------*/
  412. err:
  413.       strcpy (request, s1);
  414.  
  415.       *recno = -1;
  416.       if (sptr) status_line("!%s Request Err: %s", updreq?"Update":"File", sptr);
  417.       return NULL;
  418.    
  419.    end
  420.